package com.wangzhenyu.common.design

abstract class MySingleton<in P, out T> {

    @Volatile
    private var instance: T? = null

    protected abstract val creator: (P) -> T

    fun getInstance(parameter: P): T =
        instance ?: synchronized(this) {
            instance ?: creator(parameter).also {
                instance = it
            }
        }

}


